package com.slfx.schedule;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author zengqingfa
 * @className ScheduleMethodTest
 * @description
 * @create 2022/8/20 15:33
 */
public class ScheduleMethodTest {
    public static void main(String[] args) {
        ScheduledExecutorService respScheduler = new ScheduledThreadPoolExecutor(2);
        long startTime = System.currentTimeMillis()/1000;
        System.out.println("task begin:"+startTime);
        respScheduler.schedule(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+"--task run:"+(System.currentTimeMillis()/1000-startTime)+"s");
            }
        },2, TimeUnit.SECONDS);
    }
}